﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lepton_Practical_MVVM_6_1.Services {
    internal class MenuService : IMenuService {

        private readonly ViewModels.ShellViewModel vm;

        internal MenuService(ViewModels.ShellViewModel vm) {
            this.vm = vm;
        }

        #region IMenuService Members

        public void RegisterMenu(
            string newItemDisplayName, 
            string parentDisplayName, 
            Type view, 
            Uri iconURI = null) {

            Models.MyMenuItem menuItem;
            if (parentDisplayName == null) {
                menuItem = vm.MainMenu;
            } else {
                menuItem = vm.MainMenu.Search(x => x.Header == parentDisplayName);
                if (menuItem == null) {
                    throw new ArgumentOutOfRangeException("parentDisplayName");
                }
            }
            menuItem.Child.Add(new Models.MyMenuItem() {
                Header = newItemDisplayName,
                IconURI = iconURI,
                ViewToOpen = view
            });
        }

        #endregion
    }
}
